import { createRouter, createWebHashHistory } from 'vue-router'
// import Kecheng from './components/KeCheng.vue'
// import Zhibo from './components/ZhiBo.vue'

const router = createRouter({
    // 什么模式：hash模式 还是 history模式
    history: createWebHashHistory(),
    // 路由配置
    routes:[
        {
            path: '/',
            redirect: '/kecheng' // 重定向到课程页面
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('./components/Login.vue') 
         },
        {
           path: '/kecheng',
           component: () => import('./components/KeCheng.vue') 
        },
        {
            path: '/zhibo',
            component: () => import('./components/ZhiBo.vue') 
        },
        {
            path: '/movie',
            component: () => import('./components/Movie.vue'),
            children: [
                {
                    // 子路由（二级路由）
                    path:'xiju',
                    component:() => import('./components/pages/Xiju.vue')
                },
                {
                    // 子路由
                    path:'kongbu',
                    component:() => import('./components/pages/Kongbu.vue')
                },
            ] 
        },
        {
            path: '/tieba',
            component: () => import('./components/Tieba.vue'),
            children: [
                {
                    path: ':id', // 只要你是/tieba/xxxxxx 格式都可以匹配到下边的组件
                    name:'tiezi', // 路由命名
                    component: () => import('./components/pages/Tie.vue'),
                    props: true // 开启props传参
                },
            ] 
        },
    ]
})
router.beforeEach((to, from, next) =>{
    console.log(to, from)
    let isLogin = false;  // 假设用户没有登录
    if(to.name === 'tiezi') {
        if(isLogin) {
            next()
        } else {
            next('/login')
        }
    } else {
        next()
    }
})
export default router;